import urllib.request
import json
import jsonpath


if __name__ == '__main__':
    url = 'https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1705975503168_104&jsoncallback=jsonp105&action=cityAction&n_s=new&event_submit_doGetAllRegion=true'

    headers = {
        'Accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
        'Bx-V': '2.5.8',
        'Cookie': 'cna=OZpDGl2f2l8CAXW9w2vtMZ4x; t=7852143001f043d64b40a521d3b7bff8; xlly_s=1; tb_city=110100; tb_cityName="sbG+qQ=="; cookie2=17968ec2569fa9817414b314506180e2; v=0; _tb_token_=e3831053378fb; isg=BJKSS2lFI4Lm2F__l4xBY6Tc41h0o5Y9b9kcc1zr3sUwbzJpRDMDTdqJ38vTGg7V; tfstk=e3OM3CNw1dW_Y6VWJhCs9aS0GEDdCl1fLnFADsIqLMSBMFH6kjlDx364MA1OnsxFvCI9W1z6d3Lz6CH1MSf1Gso-2bh85F1fgAhn68YsakPo10h-wFkN5sLE2V1eB3she-VwESOtSTIurO2qaIGChg8NbFL9TdqR4FR3gSSFSO097MV4gBsyoJyPHAPf8qdUh-6NRwjRB38gqIzu-Ngn-8M1Qw_t2I333fBNRNsS-227jO7CWd5..',
        'Referer': 'https://dianying.taobao.com/',
        'Sec-Ch-Ua': '"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"',
        'Sec-Ch-Ua-Mobile': '?0',
        'Sec-Ch-Ua-Platform': '"Windows"',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
        'X-Requested-With': 'XMLHttpRequest',
    }

    request = urllib.request.Request(url = url,headers = headers)
    opens = urllib.request.urlopen(request)
    com = opens.read().decode('utf-8')
    com = com.split('(')[1].split(')')[0]
    df = open('../../爬取的文件/淘票票.json', 'w', encoding='utf-8')
    df.write(com)
    fs = json.load(open('../../爬取的文件/淘票票.json', 'r', encoding='utf-8'))
    print(jsonpath.jsonpath(fs, '$..regionName'))




